let sinon = require("sinon");
let main = require("../lib/main");
describe('main()', () => {

    it('should display main menu once started', () => {
        sinon.spy(console, 'log');
        main.main();
        expect(console.log.args.join()).toBe(`1. 添加学生
2. 生成成绩单
3. 退出
请输入你的选择（1～3）：`);
    });
    it('输入信息',function(){
        spyOn(console, 'log');
        main.tip();
        expect(console.log).toHaveBeenCalledWith(`请输入学生信息（格式：姓名, 学号, 民族, 班级, 数学: 成绩, 语文: 成绩，英语: 成绩， 编程: 成绩），按回车提交：`);
    })
    it("分开字符串",function(){
        let collection=[],t=['我','1','汉族','1701','90','90','90','90'];
        collection=main.part(collection,t);
        expect(collection).toEqual([ { name: '我',
        num: '1',
        math: 90,
        chinese: 90,
        english: 90,
        computer: 90,
        sum: 360,
        average: 90 } ])
    })
    it('中位数',function(){
        let collection=[],t=['我','1','汉族','1701','90','90','90','90'];
        collection=main.part(collection,t);
        t=['你','2','汉','1701','80','80','80','80'];
        collection=main.part(collection,t);
        let middle=main.middle(collection);
        expect(middle).toEqual(340);
    })

});
